#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 27 11:05:36 2018

@author: chenliheng
"""

# 字典
person = {'name':'mike','age':19, 'address':'北京海淀区'}

print(person['name'])

# 动态添加
person['level'] = 20

# 调用key之前，检验是否存在
if 'level' in person.keys():
    print(person['level'])
    
    
# [3,4,5,4,6,3,7,9,4,2,7,2] 动态统计出list中每个数值出现次数
# {key:value}  key: list中数值 value:出现次数

num_count = {}    
for num in [3,4,5,4,6,3,7,9,4,2,7,2]:
    if num in num_count.keys():
        num_count[num] += 1
    else:
        num_count[num] = 1

# 遍历字典
#for item in num_count.items():
#    print("{}:{}".format(item[0], item[1]))
        
for key,val in num_count.items():
    print("{}:{}".format(key, val))
    
    
key,val = (3,2)

